
#include "index_accessor.h++"
#include "mapped_file.h++"
#include "word_tree.h++"

class Serializer : public IndexAccessor<WritableMappedMemory> {


	typedef PointerTo<MemoryMappedPascalString> pointer_to_path;
	typedef std::map<std::string, pointer_to_path> basepath_map;
	basepath_map known_directories;
	pointer_to_path serialize_this_path(const std::string& string);
	
	
	typedef PointerTo<Document> pointer_to_document;
	typedef std::map<const UnserializedDocument*, pointer_to_document> documents_map;
	documents_map known_maps;
	
	pointer_to_document get_document_position(const UnserializedDocument& document);
	PointerTo<DetailedDataHeader> serialize_detailed_info(
		const WordTree::UnserializedNode& node);

	typedef WordTree::UnserializedNode::UnserializedMatchingDocument mtdoc;
public:
	// documents should be serialize before nodes.
	pointer_to_document serialize_document(const UnserializedDocument& document);
	// obviously, it's better to serialize postings BEFORE USING TEHM.
	PointerTo<PostingData> serialize_postings(const mtdoc& postings);

	PointerTo<WordTree::NodeHeader> serialize_node_header(const WordTree::UnserializedNode& node);

	

	Serializer() : IndexAccessor<WritableMappedMemory>() {}
};
